package com.lzh.chatnote.user.dao;

import com.lzh.chatnote.user.domain.entity.UserRole;
import com.lzh.chatnote.user.mapper.UserRoleMapper;
import com.lzh.chatnote.user.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户角色关系表 服务实现类
 * </p>
 *
 * @author lzh
 * @since 2025-06-06
 */
@Service
public class UserRoleDao extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    public List<Long> queryUserRoleIds(Object loginId) {
        return Optional.ofNullable(lambdaQuery().eq(UserRole::getUid, loginId)
                .list()).orElse(Collections.emptyList()).stream().map(UserRole::getRoleId)
                .collect(Collectors.toList());
    }
}
